<?php
namespace Admin\Controller;
use Admin\Controller;

class WithdrawController extends BaseController
{
    /**
     * 文章列表
     * @return [type] [description]
     */
    public function index($key="")
    {
        if($key == ""){
            $model = D('mempay'); 
        }else{
            $where['title'] = array('like',"%$key%");
            $where['_logic'] = 'or';
            $model = D('mempay')->where($where); 
        } 
        
        $count  = $model->where($where)->count();// 查询满足要求的总记录数
        $Page = new \Extend\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $list = $model->limit($Page->firstRow.','.$Page->listRows)->where($where)->order('id DESC')->select();
        $tmps = array();
        foreach($list as $row){
            $row['m_true_name'] = $this->get_mem_name($row['m_id']);
            if($row['status'] == 0){
                $row['status'] = '审核中';
            }
            
            if($row['status'] == 1){
                $row['status'] = '成功';
            }
            
            if($row['status'] == 2){
                $row['status'] = '失败';
            }
            $tmps[] = $row;
        }
        $this->assign('model', $tmps);
        $this->assign('page',$show);
        $this->display();     
    }
    
    public function get_mem_name($id){
        $t = M("member")->where("id=".$id)->find();
        return $t['true_name']."(微信:".$t['wechat'].")";
    }
    
    public function chg_status()
    {
        if (IS_POST) {
            $model = D("mempay");
            $status = I("post.status");
            $id = I("post.id");
            if($model->where('id='.$id)->save(array("status"=>$status, 'end_time'=>date("Y-m-d H:i:s"))) === false){
                echo 0;
            }else{
                echo 1;
            }
        }
    }
   
    public function delete($id)
    {
        $model = M("mempay");
        $result = $model->where("id=".$id)->delete();
        if($result){
            $this->success("删除成功", U('withdraw/index'));
        }else{
            $this->error("删除失败");
        }
    }
}
